import React from 'react';
import {injectIntl, language} from './intl';
import PropTypes from 'prop-types';
import {Button, Form, Row, Col, Modal, Card, Spin, message} from 'antd';
import routes from './routes';
import {FORM_OPTIONS, PAGE, FORM_ROW_OPTIONS} from '../constants';
import {exportDownload} from '../utils';
import {PERMISSION, dealerConditions} from './constants';
import WrappedDatePicker from '../common/WrappedDatePicker';
import WrappedSelect from '../common/WrappedSelect';
import styles from './style.css';
import FileUpload from './FileUpload';
import {validateAdd} from './utils';
import Return from '../common/Return';
import VehicleSoldPanel from './VehicleSoldPanel';
import FaultItemPanel from './FaultItemPanel';
import SupplierPanel from './SupplierPanel';
import SearchInput from 'Shared/components/SearchInput';
import DealerSelectPanel from '../common/DealerSelect/SelectEdit';
import {getDealerSimple, getDealers} from './api';
import TextInput from 'Shared/components/TextInput';
import WrappedInputNumber from '../common/WrappedInputNumber';
import {consultType, technicalSupportTransmissionType} from '../Enum';
const FormItem = Form.Item;
const EMPTY_ARRAY = [];
export class Add extends React.PureComponent {
    state = {
        loading: false,
        hasOperat: false,
        isValidate: false,
        showPanel: false,
        showVehicleSoldPanel: false,
        showFaultItemPanel: false,
        showSupplierPanel: false,
        isSearch: false,
        searchPartCode: ''
    };

    componentDidMount() {
        this.props.init();
        this.ismounted = true;
    }

    componentWillUnmount() {
        this.ismounted = false;
        this.props.onUmount();
    }

    handleFilterChange = (value, name) => {
        if(!this.state.hasOperat)
            this.setState({
                hasOperat: true
            });
        this.props.onConditionsChange(name, value);
    };
    // eslint-disable-next-line react/sort-comp
    onChange = (value, name, e) => {
        const {applyid, id} = e.target.dataset;
        const data = {
            value,
            claimId: applyid,
            id,
            isDetailsRemark: true
        };
        this.props.onConditionsChange(name, data);
    }
    showPanel = () => {
        this.setState({
            showPanel: !this.state.showPanel
        });
    };
    onClickDelete = e => {
        const {id, applyid, uid} = e.target.dataset;
        this.setState({
            hasOperat: true,
            currentApplyId: '',
        });
        this.props.onDeleteDetail({
            uid,
            id,
            claimId: applyid
        });
    };

    onSubmit = () => {
        const {attachments = []} = this.props.conditions;
        const result = validateAdd(this.props.conditions, this.props.id);
        if(result) {
            this.setState({
                isValidate: true,
            });
            return message.warn(result);
        }
        if(!attachments.length)
            return Modal.confirm({
                title: this.props.intl.formatMessage({
                    id: 'add.onSubmit.title',
                    defaultMessage: '附件清单为空，是否继续提交'
                }),
                onOk: () => {
                    this.setState({
                        loading: true
                    });
                    this.props.onSubmit().then(success => {
                        if(this.ismounted && !success)
                            this.setState({
                                loading: false
                            });
                    });
                }
            });
        this.setState({
            loading: true
        });
        return this.props.onSubmit().then(success => {
            if(this.ismounted && !success)
                this.setState({
                    loading: false
                });
        });
    };

    onClickAddDetail = () => {
        if(this.state.isSearch)
            return message.warn(this.props.intl.formatMessage({
                id: 'add.onClickAddIsSearch.message',
                defaultMessage: '请先取消筛选清单'
            }));
        if(!this.props.id && !this.props.conditions.dealerId)
            return message.warn(this.props.intl.formatMessage({
                id: 'add.onClickAddDetail.message',
                defaultMessage: '请先选择总代'
            }));
        this.setState({showPanel: true});
    }

    onSelectDealer = data => {
        const {dealerId, details = []} = this.props.conditions;
        if(!data.id || data.id === dealerId) return;
        if(!this.state.hasOperat)
            this.setState({
                hasOperat: true
            });
        if(dealerId && details.length)
            Modal.confirm({
                title: this.props.intl.formatMessage({
                    id: 'add.onSelectDealer.title',
                    defaultMessage: '变更总代，将会清空清单，是否清空？'
                }),
                onOk: () => {
                    this.props.onSelectDealer(data);
                }
            });
        else
            this.props.onSelectDealer(data);
    }
    
    handleReset = clearFilters => {
        clearFilters();
        this.setState({searchText: ''});
    };
    onClickStopPropagation = e => {
        e.stopPropagation();
    }
    onDeleteAll = () => {
        this.props.onIsSearch({
            isSearch: false,
            newDetails: []
        });
        this.setState({
            isSearch: false,
            searchPartCode: ''
        });
        this.props.onDeleteAll();
    }
    onClickSearchSupplierBtn = () => {
        this.setState({
            showSupplierPanel: true
        });
    }
    onSelectSupplier = records => {
        this.props.onConditionsChange('supplierId', records.id);
        this.props.onConditionsChange('supplierCode', records.code);
        this.props.onConditionsChange('supplierName', records.name);
        this.setState({
            hasOperat: true,
            showSupplierPanel: false
        });
    }
    onCancelSupplier = () => {
        this.setState({showSupplierPanel: false});
    }
    onClickSearchFaultItemBtn = () => {
        this.setState({
            showFaultItemPanel: true
        });
    }
    onSelectFaultItem = records => {
        this.props.onConditionsChange('faultItemId', records.id);
        this.props.onConditionsChange('faultItemCode', records.code);
        this.props.onConditionsChange('faultItemName', records.name);
        this.setState({
            hasOperat: true,
            showFaultItemPanel: false
        });
    }
    onCancelFaultItem = () => {
        this.setState({showFaultItemPanel: false});
    }
    onClickSearchVehicleSoldBtn = () => {
        this.setState({
            showVehicleSoldPanel: true
        });
    }
    onSelectVehicleSold = records => {
        this.props.onConditionsChange('vin', records.vin);
        this.props.onConditionsChange('productCategoryId', records.id);
        this.props.onConditionsChange('productCategoryCode', records.productCategoryCode);
        this.props.onConditionsChange('engineCode', records.engineCode);
        this.props.onConditionsChange('annoucementNumber', records.annoucementNumber);
        this.props.onConditionsChange('engineModel', records.engineModel);
        this.props.onConditionsChange('transmissionSn', records.transmissionSn);
        this.props.onConditionsChange('productionDate', records.productionDate);
        this.props.onConditionsChange('saleDate', records.saleDate);
        this.setState({
            hasOperat: true,
            showVehicleSoldPanel: false
        });
    }
    onCancelVehicleSold = () => {
        this.setState({showVehicleSoldPanel: false});
    }
    onChangeUpload = data => {
        if(!this.state.hasOperat)
            this.setState({
                hasOperat: true
            });
        this.props.updateAttachments(data);
    }
    onChangeRemove= data => {
        if(!this.state.hasOperat)
            this.setState({
                hasOperat: true
            });
        this.props.removeAttachments(data);
    }
    render() {
        const {attachments = []} = this.props.conditions;
        const dealerInfo = this.props.conditions.dealerId ? {
            id: this.props.conditions.dealerId,
            code: this.props.conditions.dealerCode,
            name: this.props.conditions.dealerName
        } : null;
        const queryCondition = {
            ...dealerConditions,
            brandId: this.props.conditions.brandId
        };
        const dealerComp = this.props.conditions.brandId ? (<DealerSelectPanel
            allowClear={false}
            value={dealerInfo}
            getDealerSimple={getDealerSimple}
            getDealers={getDealers}
            conditions={queryCondition}
            onSelect={this.onSelectDealer} />) : (<TextInput name="dealerId"
            value={''} disabled placeholder={this.props.intl.formatMessage({
                id: 'add.dealerComp.placeholder',
                defaultMessage: '请先选择品牌'
            })} />);
        return (
            <div className={styles.detail}>
                <Spin spinning={this.props.loading || this.state.loading}>
                    <Form className="form-standard">
                        <Card
                            className={styles.marginBottom}
                            title={this.props.intl.formatMessage({
                                id: 'add.card.title',
                                defaultMessage: '基本信息'
                            })}>
                            <Row>
                                <Col key="code" {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'add.form.code',
                                            defaultMessage: '编号'
                                        })}
                                        {...FORM_OPTIONS.item}>
                                        <span className="value-font">{this.props.id ? this.props.conditions.code : this.props.intl.formatMessage({
                                            id: 'add.form.code.noData',
                                            defaultMessage: '<尚未生成>'
                                        })}</span>
                                    </FormItem>
                                </Col>
                                {this.props.brands.length > 1 ? <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'add.form.brandId',
                                            defaultMessage: '品牌'
                                        })}
                                        {...FORM_OPTIONS.item}
                                        validateStatus={this.state.isValidate && !this.props.conditions.brandId ? 'error' : null}
                                        required={!this.props.id}>
                                        {this.props.id ? <span className="value-font">{this.props.conditions.brandCode}</span>
                                            : <WrappedSelect
                                                name="brandId"
                                                value={this.props.conditions.brandId}
                                                options={this.props.brands}
                                                onChange={this.handleFilterChange} />}
                                    </FormItem>
                                </Col> : null}
                                {!this.props.isDealerUser && <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'add.form.telPhone',
                                            defaultMessage: '联系电话'
                                        })}
                                        {...FORM_OPTIONS.item}>
                                        {this.props.enterprise ? this.props.enterprise.telPhone : ''}
                                    </FormItem>
                                </Col>}
                                {!this.props.isDealerUser && <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'add.form.email',
                                            defaultMessage: '邮箱'
                                        })}
                                        {...FORM_OPTIONS.item}>
                                        {this.props.enterprise ? this.props.enterprise.email : ''}
                                    </FormItem>
                                </Col>}
                                
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={this.props.intl.formatMessage({
                                        id: 'add.form.vin',
                                        defaultMessage: 'VIN'
                                    })} {...FORM_OPTIONS.item}
                                    validateStatus={this.state.isValidate && !this.props.conditions.vin ? 'error' : null}
                                    required>
                                        <SearchInput
                                            disabled={true}
                                            value={this.props.conditions.vin}
                                            onClickSearchBtn={() => this.onClickSearchVehicleSoldBtn()} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={this.props.intl.formatMessage({
                                        id: 'add.form.engineCode',
                                        defaultMessage: '发动机号'
                                    })} {...FORM_OPTIONS.item} >
                                        <TextInput
                                            name="engineCode"
                                            value={this.props.conditions.engineCode}
                                            onBlur={this.handleFilterChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={this.props.intl.formatMessage({
                                        id: 'add.form.engineModel',
                                        defaultMessage: '发动机型号'
                                    })} {...FORM_OPTIONS.item}
                                    validateStatus={this.state.isValidate && !this.props.conditions.engineModel ? 'error' : null}
                                    required>
                                        <TextInput
                                            name="engineModel"
                                            value={this.props.conditions.engineModel}
                                            onBlur={this.handleFilterChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={this.props.intl.formatMessage({
                                        id: 'add.form.transmissionSn',
                                        defaultMessage: '变速箱号'
                                    })} {...FORM_OPTIONS.item}>
                                        <TextInput
                                            name="transmissionSn"
                                            value={this.props.conditions.transmissionSn}
                                            onBlur={this.handleFilterChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={this.props.intl.formatMessage({
                                        id: 'add.form.productionDate',
                                        defaultMessage: '生产日期'
                                    })} {...FORM_OPTIONS.item}
                                    validateStatus={this.state.isValidate && !this.props.conditions.productionDate ? 'error' : null}
                                    required>
                                        <div onClick={this.onClickStopPropagation}><WrappedDatePicker
                                            name="productionDate"
                                            value={this.props.conditions.productionDate}
                                            onChange={this.handleFilterChange}/></div>
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={this.props.intl.formatMessage({
                                        id: 'add.form.saleDate',
                                        defaultMessage: '销售日期'
                                    })} {...FORM_OPTIONS.item}
                                    validateStatus={this.state.isValidate && !this.props.conditions.saleDate ? 'error' : null}
                                    required>
                                        <div onClick={this.onClickStopPropagation}><WrappedDatePicker
                                            name="saleDate"
                                            value={this.props.conditions.saleDate}
                                            onChange={this.handleFilterChange}/></div>
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={this.props.intl.formatMessage({
                                        id: 'add.form.productCategoryId',
                                        defaultMessage: '车型编号'
                                    })}{...FORM_OPTIONS.item}>
                                        {this.props.conditions.productCategoryCode}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={this.props.intl.formatMessage({
                                        id: 'add.form.annoucementNumber',
                                        defaultMessage: '公告号'
                                    })}{...FORM_OPTIONS.item}>
                                        {this.props.conditions.annoucementNumber}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'queryPanel.form.consultType',
                                            defaultMessage: '咨询类型'
                                        })}
                                        {...FORM_OPTIONS.item}
                                        validateStatus={this.state.isValidate && !this.props.conditions.consultType ? 'error' : null}
                                        required>
                                        <div onClick={this.onClickStopPropagation}><WrappedSelect
                                            name="consultType"
                                            value={this.props.conditions.consultType}
                                            options={consultType.toList(language)}
                                            onChange={this.handleFilterChange} /></div>
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={this.props.intl.formatMessage({
                                        id: 'add.form.faultDate',
                                        defaultMessage: '故障日期'
                                    })} {...FORM_OPTIONS.item}
                                    validateStatus={this.state.isValidate && !this.props.conditions.faultDate ? 'error' : null}
                                    required>
                                        <div onClick={this.onClickStopPropagation}><WrappedDatePicker
                                            name="faultDate"
                                            value={this.props.conditions.faultDate}
                                            onChange={this.handleFilterChange}/></div>
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={this.props.intl.formatMessage({
                                        id: 'add.form.faultItemId',
                                        defaultMessage: '故障代码'
                                    })} {...FORM_OPTIONS.item}
                                    validateStatus={this.state.isValidate && !this.props.conditions.faultItemId ? 'error' : null}
                                    required>
                                        <SearchInput
                                            disabled={true}
                                            value={this.props.conditions.faultItemCode ? `(${this.props.conditions.faultItemCode})${this.props.conditions.faultItemName}` : null}
                                            onClickSearchBtn={() => this.onClickSearchFaultItemBtn()} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={this.props.intl.formatMessage({
                                        id: 'add.form.mileage',
                                        defaultMessage: '故障里程'
                                    })} {...FORM_OPTIONS.item}
                                    validateStatus={this.state.isValidate && !this.props.conditions.mileage ? 'error' : null}
                                    required>
                                        <WrappedInputNumber
                                            name="mileage"
                                            min={0}
                                            precision={0}
                                            value={this.props.conditions.mileage}
                                            onChange={this.handleFilterChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={this.props.intl.formatMessage({
                                        id: 'add.form.supplierId',
                                        defaultMessage: '供应商'
                                    })} {...FORM_OPTIONS.item}
                                    validateStatus={this.state.isValidate && !this.props.conditions.supplierId ? 'error' : null}
                                    required>
                                        <SearchInput
                                            disabled={true}
                                            value={this.props.conditions.supplierCode ? `(${this.props.conditions.supplierCode})${this.props.conditions.supplierName}` : null}
                                            onClickSearchBtn={() => this.onClickSearchSupplierBtn()} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'queryPanel.form.transmissionType',
                                            defaultMessage: '变速器类型'
                                        })}
                                        {...FORM_OPTIONS.item}
                                        validateStatus={this.state.isValidate && !this.props.conditions.transmissionType ? 'error' : null}
                                        required>
                                        <div onClick={this.onClickStopPropagation}><WrappedSelect
                                            name="transmissionType"
                                            value={this.props.conditions.transmissionType}
                                            options={technicalSupportTransmissionType.toList(language)}
                                            onChange={this.handleFilterChange} /></div>
                                    </FormItem>
                                </Col>
                            </Row>
                            <Row>
                                <Col>
                                    <FormItem label={this.props.intl.formatMessage({
                                        id: 'queryPanel.form.faultDescription',
                                        defaultMessage: '故障描述'
                                    })} {...FORM_ROW_OPTIONS.item}
                                    validateStatus={this.state.isValidate && !this.props.conditions.faultDescription ? 'error' : null}
                                    required>
                                        <TextInput
                                            name="faultDescription"
                                            value={this.props.conditions.faultDescription}
                                            onBlur={this.handleFilterChange}/>
                                    </FormItem>
                                </Col>
                            </Row>
                            <Row>
                                <Col>
                                    <FormItem label={this.props.intl.formatMessage({
                                        id: 'queryPanel.form.measureEffects',
                                        defaultMessage: '已采取措施及效果'
                                    })} {...FORM_ROW_OPTIONS.item}
                                    validateStatus={this.state.isValidate && !this.props.conditions.measureEffects ? 'error' : null}
                                    required>
                                        <TextInput
                                            name="measureEffects"
                                            value={this.props.conditions.measureEffects}
                                            onBlur={this.handleFilterChange}/>
                                    </FormItem>
                                </Col>
                            </Row>
                            <Row>
                                <Col>
                                    <FormItem label={this.props.intl.formatMessage({
                                        id: 'queryPanel.form.suggestion',
                                        defaultMessage: '相关建议'
                                    })} {...FORM_ROW_OPTIONS.item}
                                    validateStatus={this.state.isValidate && !this.props.conditions.suggestion ? 'error' : null}
                                    required>
                                        <TextInput
                                            name="suggestion"
                                            value={this.props.conditions.suggestion}
                                            onBlur={this.handleFilterChange}/>
                                    </FormItem>
                                </Col>
                            </Row>
                        </Card>
                        <Card title={this.props.intl.formatMessage({
                            id: 'reportPanel.title.files',
                            defaultMessage: '附件清单'
                        })}>
                            <Row>
                                <Col {...FORM_OPTIONS.col}>
                                    <FileUpload onChange={this.onChangeUpload}
                                        onRemove={this.onChangeRemove}
                                        fileList={attachments}/>
                                </Col>
                            </Row>
                        </Card>
                        {
                            this.state.showVehicleSoldPanel && <VehicleSoldPanel
                                selectKey="id"
                                onCancel={this.onCancelVehicleSold}
                                onSelect={this.onSelectVehicleSold} />
                        }
                        {
                            this.state.showFaultItemPanel && <FaultItemPanel
                                selectKey="id"
                                onCancel={this.onCancelFaultItem}
                                onSelect={this.onSelectFaultItem} />
                        }
                        {
                            this.state.showSupplierPanel && <SupplierPanel
                                selectKey="id"
                                onCancel={this.onCancelSupplier}
                                onSelect={this.onSelectSupplier} />
                        }
                        {this.props.submitable && (
                            <Card type="inner">
                                <Row>
                                    <Col className="col-align-right">
                                        <Button
                                            key="submit"
                                            loading={this.state.loading}
                                            onClick={this.onSubmit}
                                            type="primary">
                                            {this.props.intl.formatMessage({
                                                id: 'add.btn.submit',
                                                defaultMessage: '保存'
                                            })}
                                        </Button>
                                    </Col>
                                </Row>
                            </Card>
                        )}
                    </Form>
                </Spin>
                <div className="page-toolbar">
                    <Return
                        disabled={this.state.loading}
                        showWarning={this.state.hasOperat}
                        onConfirm={this.props.onCancel} />
                </div>
            </div>
        );
    }
}
Add.propTypes = {
    brands: PropTypes.array.isRequired,
    conditions: PropTypes.object.isRequired,
    init: PropTypes.func.isRequired,
    isDealerUser: PropTypes.bool.isRequired,
    loading: PropTypes.bool.isRequired,
    removeAttachments: PropTypes.func.isRequired,
    submitable: PropTypes.bool.isRequired,
    updateAttachments: PropTypes.func.isRequired,
    onCancel: PropTypes.func.isRequired,
    onConditionsChange: PropTypes.func.isRequired,
    onDeleteAll: PropTypes.func.isRequired,
    onDeleteDetail: PropTypes.func.isRequired,
    onSubmit: PropTypes.func.isRequired,
    onUmount: PropTypes.func.isRequired,
    enterprise: PropTypes.object,
    intl: PropTypes.object
};
import {connect} from 'react-redux';
import {
    saveSubmitCondition,
    clearData,
    tableSearch,
    onSubmit,
    getEditInitData,
    selectClaim,
    deleteAllDetail,
    deleteDetail,
    selectDealerForAdd,
    isSearch,
    updateAttachments,
    removeAttachments,
    onSearch
} from './actions';
import {createSelector} from 'reselect';

const getBrands = createSelector(
    state => state.getIn(['page', 'domainData', 'brands', 'data']),
    brands => {
        const data = brands.toJS() || EMPTY_ARRAY;
        return data.map(item => ({
            value: item.id,
            text: item.name
        }));
    }
);
import selectorFactory from 'Shared/utils/immutableToJsSelectorFactory';
const getSubmitData = selectorFactory(['page', 'appState', 'submitData']);
const getPermissions = createSelector(
    state => state.getIn(['page', 'domainData', 'permission', 'data']),
    (state, ownProps) => ownProps.id,
    state => state.getIn(['page', 'domainData', 'detail', 'data']),
    (permissions, id, detail) => {
        const {options = EMPTY_ARRAY} = detail.toJS();
        const data = permissions.toJS();
        const submitable = id ? data.includes(PERMISSION.update) && options.includes(PERMISSION.update)
            : data.includes(PERMISSION.add);
        return submitable;
    }
);

const mapStateToProps = (state, ownProps) => ({
    id: ownProps.id,
    submitable: getPermissions(state, ownProps),
    isDealerUser: state.getIn(['page', 'domainData', 'initData', 'isDealerUser']),
    enterprise: state.getIn(['page', 'domainData', 'initData', 'enterprise']),
    loading: state.getIn(['page', 'domainData', 'detail', 'isFetching']),
    conditions: getSubmitData(state),
    brands: getBrands(state),
});

const mapDispatchToProps = (dispatch, ownProps) => ({
    init: () => dispatch(getEditInitData(ownProps.id)),
    onConditionsChange: (name, value) => dispatch(saveSubmitCondition(name, value)),
    updateAttachments: data => dispatch(updateAttachments(data)),
    removeAttachments: ({id}) => dispatch(removeAttachments(id)),
    onSubmit: () =>
        dispatch(onSubmit(ownProps.id, ownProps.isSubmit)).then(res => {
            if(res.ok) {
                dispatch(tableSearch({
                    pageIndex: PAGE.index
                }));
                ownProps.history.push(routes.query.url());
            }
            return res.ok;
        }),
    onCancel: () => {
        ownProps.history.push(routes.query.url());
    },
    onUmount: () => dispatch(clearData()),
    onSelectDealer: data => dispatch(selectDealerForAdd(data)),
    onDeleteAll: () => dispatch(deleteAllDetail()),
    onDeleteDetail: data => dispatch(deleteDetail(data)),
    onIsSearch: data => dispatch(isSearch(data)),
    onSearch: data => dispatch(onSearch(data))
});


export default connect(
    mapStateToProps,
    mapDispatchToProps
)(injectIntl(Add));
